package com.liwc.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageInfo;
import com.liwc.message.ResponseMessage;
import com.liwc.model.Notepad;
import com.liwc.model.page.EasyuiPageModel;
import com.liwc.service.NotepadService;

/**
 * 
 * 模块：基于RBAC的基础权限框架demo
 * <br/>描述：记事本管理
 * @author liwc
 * @date 2018年7月1日 上午11:31:18
 * @类名 NotepadController
 */
@Controller
@RequestMapping(value="business/notepad")
public class NotepadController {

	private static Logger log = LoggerFactory.getLogger(NotepadController.class);
	
	private static final String PERFIX = "business/notepad";
	

	// 账户类型service
	@Autowired
	private NotepadService service;
	
	
	/**
	 * 打开首页
	 * @param req
	 * @param resp
	 * @return
	 */
	@RequestMapping(value="index")
	public String index(Model m){
		m.addAttribute("title", "记事本管理");
		return PERFIX+"/index";
	}
	
	/**
	 * 查询列表
	 * @param dto
	 * @return
	 */
	@RequestMapping(value = "list")
	@ResponseBody
	public EasyuiPageModel list(Notepad dto) {
		PageInfo<Notepad> pi = service.findAll(dto);
		log.debug("----->总数量："+ pi.getTotal() +",分页数量："+ pi.getList().size());
		return new EasyuiPageModel(pi.getTotal(), pi.getList());
	}
	
	
	
	
	@RequestMapping(value = "info")
	public String info(Integer id, Model model) {
		Notepad dto = service.findById(id);
		model.addAttribute("vo", dto);
		return PERFIX+"/info";
	}
	
	
	
	@RequestMapping(value = "save", method=RequestMethod.POST)
	@ResponseBody
	public ResponseMessage save(Notepad record) {
		return service.save(record);
	}
	
	
	
	@RequestMapping(value= "/delete/{id}", method=RequestMethod.POST)
	@ResponseBody
	public ResponseMessage delete(@PathVariable("id") Integer id){
		return service.deleteById(id);
	}
	
	
	
}
